package cn.huaguo.trigger.http;

import cn.huaguo.domain.wallet.model.entity.WalletEntity;
import cn.huaguo.domain.wallet.service.IWalletService;
import cn.huaguo.types.context.BaseContext;
import cn.huaguo.types.enums.ResponseCode;
import cn.huaguo.types.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @Author：Arvin
 * @description：钱包controller
 * @Date：2024/5/19 17:42
 */

@Slf4j
@RestController
@RequestMapping("/wallet")
public class WalletController {
    @Resource
    private IWalletService walletService;

    /**
     * 获取钱包余额
     *
     * @return
     */
    @GetMapping("/walletInfo")
    public Response<WalletEntity> getWalletInfo() {
        try {
            log.info("获取钱包余额信息");
            String userId = BaseContext.getCurrentId();
            WalletEntity walletEntity = walletService.getWalletInfo(userId);
            log.info("查询当前用户相关订单列表:{}", walletEntity);
            return Response.<WalletEntity>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(walletEntity)
                    .build();
        } catch (Exception e) {
            log.error("查询失败当前订单信息: {}, message: {}", walletService, e.getMessage());
            return Response.<WalletEntity>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }
}
